package com.easy.auth.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.easy.auth.domain.Department;
import com.easy.auth.service.DepartmentService;
import com.easy.common.web.PagedList;
import com.easy.common.web.message.DeleteMessage;
import com.easy.common.web.message.Message;
import com.easy.common.web.message.SaveOrEditMessage;

@Controller
@RequestMapping("DepartmentController")
public class DepartmentController {

	@Autowired
	private DepartmentService departmentService;

	@RequestMapping("goToDepartmentManager")
	public String goToActionManager(String secondMenuId,HttpServletRequest request) {
		request.getSession().setAttribute("secondMenuId", secondMenuId);
		return "auth/department";
	}

	/**
	 * 查询全部节点数据
	 * 
	 * @return
	 */
	@RequestMapping("getDepartmentList")
	@ResponseBody
	public PagedList<Department> getDepartmentList() {
		return departmentService.getAllDepartments();
	}

	/**
	 * 根据oid查询该节点其他数据
	 * 
	 * @return
	 */
	@RequestMapping("findDepartmentById")
	@ResponseBody
	public Department findDepartmentById(Department department) {
		return departmentService.findDepartmentById(department);
	}

	/**
	 * 保存资源信息
	 * 
	 * @param param
	 * @param request
	 * @return
	 */
	@RequestMapping("saveDepartmentItem")
	@ResponseBody
	public Message saveTreegridItem(Department department) {
		int count = departmentService.saveDepartment(department);
		return new SaveOrEditMessage(count);
	}

	/**
	 * 删除资源信息
	 * 
	 * @param param
	 * @param request
	 * @return
	 */
	@RequestMapping("removeDepartmentItems")
	@ResponseBody
	public Message removeTreegridItem(String oids) {
		String[] ids = oids.split("-");
		return new DeleteMessage(departmentService.removeDepartments(ids));
	}

}
